/* eslint-disable prettier/prettier */
import Icon from '@/components/Icon/Icon.vue';
import { BasicColumn, FormSchema } from '@/components/Table';
import { defHttp } from '@/utils/http/axios';
import { ifShow, ifDescription } from '@/utils/schema_util'
import { h } from 'vue';
/**
 * 表格列配置
 */
export const tableColumns: BasicColumn[] = [
  {
    title: '菜单名称',
    dataIndex: 'name',
    component: 'Input',
    align: 'left',
    componentProps: {
      placeholder: "请输入菜单名称",
    },
    customRender: ({ record }) => {
      return record.icon?h('span', {},[
        h(Icon, {
          icon: record.icon,
        }),
        h('span', {
          style: {
            marginLeft: '4px',
          }
        }, record.name)
      ]):h('span', {}, record.name)
    },
  },
  {
    title: '菜单类型',
    dataIndex: 'type',
    component: 'ApiDict',
    componentProps: {
      code: "sys_menu_type",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择菜单类型",
    }
  },
  {
    title: '唯一编码',
    dataIndex: 'code',
    component: 'Input',
    componentProps: {
      placeholder: "请输入唯一编码",
    }
  },
  {
    title: '路由/接口地址',
    dataIndex: 'path',
    component: 'Input',
    componentProps: {
      placeholder: "请输入路由/接口地址",
    }
  },
  {
    title: '操作',
    dataIndex: '__ACTION__',
    width: 140,
  },
];
/**
 * 搜索表单配置
 */
export const searchFormSchemas: FormSchema[] = [
];

/**
 * 新增、编辑表单配置
 */
export const formSchemas: FormSchema[] = [
  {
    field: 'id',
    label: '菜单ID',
    component: 'Input',
    show: false,
    description: false,
    componentProps: {
      type: "hidden",
      placeholder: "请输入菜单ID",
    } as any,
    required: false,
    colProps: { span: 24 },
    ifShow: (data) => {
      const ext = {"addHide":1,"editHide":0,"listHide":1,"viewHide":1,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"Input_type":"hidden"}
      return ifShow(data,ext);
    },
  },
  {
    field: 'type',
    label: '菜单类型',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"ApiDict_code":"sys_menu_type","ApiDict_dataType":"number","popupContainerInBody":false,"span":12,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 1,
    componentProps: {
      code: "sys_menu_type",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择菜单类型",
    } as any,
    required: true,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"ApiDict_code":"sys_menu_type","ApiDict_dataType":"number","popupContainerInBody":false,"span":12,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
  },
  {
    field: 'parentId',
    label: '上级菜单',
    component: 'ApiTreeSelect',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiTreeSelect_api":"/sys/menu/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"},"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      cacheKey: "sys:menu:tree",
      api: (params) => {
        return defHttp.post({ url: '/sys/menu/tree', params });
      },
      immediate: true,
      placeholder: "请选择上级菜单",
      labelField: "name",
      valueField: "id",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiTreeSelect_api":"/sys/menu/tree","ApiTreeSelect_immediate":true,"ApiTreeSelect_replaceFields":{"title":"name","value":"id","key":"id","children":"children"},"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'name',
    label: '菜单名称',
    component: 'Input',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入菜单名称",
    } as any,
    required: true,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'code',
    label: '唯一编码',
    component: 'Input',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入唯一编码",
    } as any,
    required: true,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":1,"search":0,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'path',
    label: '路由/接口地址',
    component: 'Input',
    helpMessage: ['route.path'],
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入路由/接口地址",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'component',
    label: '组件地址',
    component: 'Input',
    helpMessage: ['route.component'],
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入组件地址",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return ![1,2].includes(values.type)
    }
  },
  {
    field: 'openType',
    label: '打开方式',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"sys_menu_open_type","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 1,
    componentProps: {
      code: "sys_menu_open_type",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择打开方式",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"ApiDict_code":"sys_menu_open_type","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return values.type !== 2
    }
  },
  {
    field: 'icon',
    label: '菜单图标',
    component: 'IconPicker',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"IconPicker_copy":false}
      return ifDescription(data,ext);
    },
    componentProps: {
      copy: false,
      placeholder: "请输入菜单图标",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":0,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12,"IconPicker_copy":false}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return ![1,2].includes(values.type)
    }
  },
  {
    field: 'url',
    label: '内外链地址',
    helpMessage: ['url'],
    component: 'Input',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    componentProps: {
      placeholder: "请输入内外链地址",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return ![2,3].includes(values.openType)
    }
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifDescription(data,ext);
    },
    defaultValue: "999",
    componentProps: {
      placeholder: "请输入排序",
    } as any,
    required: false,
    colProps: { span: 12 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":12}
      return ifShow(data,ext);
    },
  },
  {
    field: 'enabled',
    label: '是否启用',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 1,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择是否启用",
    } as any,
    required: false,
    colProps: { span: 6 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
  },
  {
    field: 'isShow',
    label: '是否显示',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 1,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择是否显示",
    } as any,
    required: false,
    colProps: { span: 6 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return ![1,2].includes(values.type)
    }
  },
  {
    field: 'isSync',
    label: '是否同步',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"span":6,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 0,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择是否同步",
    } as any,
    required: false,
    colProps: { span: 6 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"span":6,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
  },
  {
    field: 'isCache',
    label: '是否缓存',
    component: 'ApiDict',
    description: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifDescription(data,ext);
    },
    defaultValue: 0,
    componentProps: {
      code: "yes_no",
      dataType: "number",
      renderType: "RadioGroup",
      isBtn: true,
      placeholder: "请选择是否缓存",
    } as any,
    required: false,
    colProps: { span: 6 },
    ifShow: (data) => {
      const ext = {"addHide":0,"editHide":0,"listHide":1,"viewHide":0,"addDisabled":0,"editDisabled":0,"required":0,"search":0,"span":6,"ApiDict_code":"yes_no","ApiDict_dataType":"number","popupContainerInBody":false,"ApiDict_renderType":"RadioGroup","ApiDict_isBtn":true}
      return ifShow(data,ext);
    },
    dynamicDisabled({values}){
      return ![1,2].includes(values.type)
    }
  },
];
